//
//  SpeciallCollectionViewCell.m
//  IntimateGift
//
//  Created by 蔡宏业 on 14/12/22.
//  Copyright (c) 2014年 蔡宏业. All rights reserved.
//

#import "SpeciallCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "SpecialCell.h"
@implementation SpeciallCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 背景白色
        self.backView = [[UIView alloc] init];
        self.backView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.backView];
         // 图片
        self.myImageView = [[UIImageView alloc] init];
        self.myImageView.backgroundColor = [UIColor blackColor];
        [self.backView addSubview:self.myImageView];
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.font = [UIFont boldSystemFontOfSize:12];
        self.titleLabel.textColor = [UIColor whiteColor];
        [self.myImageView addSubview:self.titleLabel];
        [_titleLabel release];
        // 喜欢个数的背景
        self.likeImageView = [[UIImageView alloc] init];
        self.likeImageView.backgroundColor = [UIColor blackColor];
        self.likeImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [self.likeImageView addGestureRecognizer:tap];
        [self.myImageView addSubview:self.likeImageView];
        // 喜欢个数
        self.likeLabel = [[UILabel alloc] init];
        [self.likeImageView addSubview:self.likeLabel];
        self.likeLabel.textColor = [UIColor whiteColor];
        self.likeLabel.textAlignment = NSTextAlignmentCenter;
        [_likeLabel release];
        // 心形图片
        self.heartImageView = [[UIImageView alloc] init];
        [self.likeImageView addSubview:self.heartImageView];
        self.heartImageView.image = [UIImage imageNamed:@"iconfont-xin.png"];
        //        self.heartImageView.backgroundColor = [UIColor clearColor];
        [self layoutSubviews];
        [_heartImageView release];
        
        [_likeImageView release];
        [_myImageView release];
        [_backView release];
        
    }
    return self;
}



- (void)tapAction:(UITapGestureRecognizer *)tap
{
    NSLog(@"1111");
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    // 上面控件的坐标
    _backView.frame = CGRectMake(5, 5, self.contentView.bounds.size.width - 10, self.contentView.bounds.size.height - 10);
    _myImageView.frame = CGRectMake(0, 0, self.backView.bounds.size.width, self.backView.bounds.size.height);
    _titleLabel.frame = CGRectMake(2, self.myImageView.bounds.size.height - self.myImageView.bounds.size.height / 2.5, self.myImageView.bounds.size.width - 2, self.myImageView.bounds.size.height / 2.5 );
//    _likeImageView.frame = CGRectMake(self.myImageView.bounds.size.width - self.myImageView.bounds.size.width / 5, 5, self.myImageView.bounds.size.width / 5 - 5, 30);
    //    _heartImageView.frame = CGRectMake(self.likeImageView.bounds.size.width - 2, self.likeImageView.bounds.size.height - 2, self.likeImageView.bounds.size.width / 3, self.likeImageView.bounds.size.height - 4);
//    _heartImageView.frame = CGRectMake(5, 5, 15, 20);
//    _likeLabel.frame = CGRectMake(20, 5, 40, 20);
    
}

// 重写setter方法
- (void)setChoiceness:(Choiceness *)choiceness
{
    if (_choiceness != choiceness) {
        [_choiceness release];
        _choiceness = [choiceness retain];
    }
    [_myImageView setImageWithURL:[NSURL URLWithString:_choiceness.cover_image_url]];
    _titleLabel.text = _choiceness.title;
    _likeLabel.text = _choiceness.likes_count;
    
}

// 内存
- (void)dealloc
{
    [_backView release];
    [_myImageView release];
    [_titleLabel release];
    [_likeImageView release];
    [_likeLabel release];
    [_heartImageView release];
    [super dealloc];
}


@end
